$(document).ready(function() {
	UploadUser.init();
});

UploadUser = {};
UploadUser.acceptFileTypes = new Array('jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG');

UploadUser.init = function() {
	
	$('#userUploadFileInput').change(function(e) {
		var fileInput = $(this);
		var file = $(this).val();
		if (file) {
			var fileType = UploadUser.getFileExtension(file);
			if ($.inArray(fileType, UploadUser.acceptFileTypes) > -1) {
				//File is oky...
			} else {
				$('#dialogErrorFileType').dialog({
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			}
		} else {
			//No file selected...
		}
	});
	
}

UploadUser.getFileExtension = function(filename) {
	var parts = filename.split('.');
	return parts[parts.length - 1];
}